﻿using System;
using Csla;
using BizControl.DalLinq;
using BizControl.Resources;

namespace BizControl.Library.BusinessObjects.BusinessRoles
{
  [Serializable()]
  public class BusinessRoleInfo : ReadOnlyBase<BusinessRoleInfo>, ISupportEmptyValue
  {
    public Guid Id { get; private set; }
    public string Name { get; private set; }

    internal BusinessRoleInfo(Guid id, string name)
    {
      Id = id;
      Name = name;
    }

    internal BusinessRoleInfo(BusinessRole role)
    {
      if (role != null)
      {
        Id = role.RoleId;
        Name = role.Name;
      }
      else
      {
        Id = Guid.Empty;
        Name = PropertiesNames.EmptyName;
      }
    }

    public BusinessRoleInfo(BusinessRoleBO role)
    {
      if (role != null)
      {
        Id = role.RoleId;
        Name = role.Name;
      }
      else
      {
        Id = Guid.Empty;
        Name = PropertiesNames.EmptyName;
      }
    }

    public BusinessRoleInfo(BusinessRoleInfo businessRoleInfo)
    {
      if (businessRoleInfo != null)
      {
        Id = businessRoleInfo.Id;
        Name = businessRoleInfo.Name;
      }
    }

    public override bool Equals(object obj)
    {
      if (obj is BusinessRoleInfo)
        return this.Id == (obj as BusinessRoleInfo).Id;
      return base.Equals(obj);
    }

    public override int GetHashCode()
    {
      return base.GetHashCode();
    }

    public override string ToString()
    {
      return Name;
    }

    #region ISupportEmtpyValue Members

    public bool IsEmpty()
    {
      return Id == Guid.Empty;
    }

    #endregion

  }
}
